/**
 * Copyright (C) 2012 he110w0r1d <http://he110w0r1d.googlecode.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${groupId};

import java.util.EnumSet;

import javax.servlet.DispatcherType;

import lombok.SneakyThrows;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.DefaultServlet;
import org.eclipse.jetty.servlet.ServletContextHandler;

import com.google.guiceberry.GuiceBerryEnvMain;
import com.google.inject.Guice;
import com.google.inject.servlet.GuiceFilter;

import ${package}.module.MyServletModule;


public class JettyServerStarter implements GuiceBerryEnvMain {

	@SneakyThrows
	public void run() {
		Server server = new Server(9999);
		server.setStopAtShutdown(true);
		
		ServletContextHandler context = new ServletContextHandler();
		context.addFilter(GuiceFilter.class, "/*", EnumSet.allOf(DispatcherType.class));
		context.addServlet(DefaultServlet.class, "/");
		server.setHandler(context);
		server.start();
	}
	
	
	@SneakyThrows
	public static final void main(String[] args) {
		Guice.createInjector(new MyServletModule());
		new JettyServerStarter().run();
		
		Thread.sleep(600000);
	}

}
